import { createStore } from "vuex"
import axios from 'axios'

const store = createStore({
  state() {
    return {
      friendData:[],
      users: [
        {
          num:3365153027,
          password:123456
        }
      ],
      speckMsg: [],
      msgList:[{}]
    }
  },
  actions:{
    getFriends({commit}){
      axios.get('http://yapi.smart-xwork.cn/mock/148417/qq/friends')
      .then(
        res => {
        commit('getFriends',res.data.data)
        },
        err => {
          console.log(err.message)
        }
      ) 
    },

    signIn({commit},userInfo){
      commit('signIn', userInfo)
    },

    puslish({commit}, msg) {
      commit('publish',msg)
    }

  },
  mutations:{
    getFriends(state,friendData) {
      state.friendData=friendData
      state.speckMsg = friendData
    },

    signIn(state,userInfo) {
      state.users.push(userInfo) 
    },

    publish(state,msg) {
      state.speckMsg.unshift(msg)
    }

  }
})

export default store